package com.rpcfx.transports;

import com.rpcfx.api.RegistryCenterService;
import com.rpcfx.api.RpcfxResolver;
import com.rpcfx.server.RpcfxInvoker;
import com.rpcfx.server.RpcfxResolverImpl;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

public class HttpInitializer extends ChannelInitializer<SocketChannel> {


    RegistryCenterService registryCenterService;

    public HttpInitializer(RegistryCenterService registryCenterService) {
        this.registryCenterService = registryCenterService;
    }

    @Override
    public void initChannel(SocketChannel ch) {
        ChannelPipeline p = ch.pipeline();
        p.addLast(new HttpServerCodec());
        //p.addLast(new HttpServerExpectContinueHandler());
        p.addLast(new HttpObjectAggregator(1024 * 1024));
        RpcfxResolver resolver = new RpcfxResolverImpl(registryCenterService);
        p.addLast(new HttpHandler(new RpcfxInvoker(resolver)));
    }
}
